/**
 * A utility class containing miscellaneous functions.
 * CS 149 Project, Phase 1
 * @author Miaoer Yu
 */

public class Util
{
    /**
     * Checks if two double values are equal.
     * @param a - first double value
     * @param b - second double value
     * @return true if the double values are equal, false otherwise
     */
    public static boolean areDoublesEqual(double a, double b)
    {
        return Math.abs(a - b) < 0.001;
    }

    /**
     * Checks if given number is a whole number (i.e. an integer)
     * @param n - the given number
     * @return true if the number is whole, false otherwise
     */
    public static boolean isWholeNumber(double n)
    {
        return Util.areDoublesEqual(n - Math.round(n), 0);
    }

    /**
     * Gives a double value to the nearest tenth
     * @param number - double value
     * @return double value to nearest tenth
     */
    public static double nearestTenth(double number)
    {
        return Double.parseDouble(String.format("%.1f", number));
    }
}

